<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="css/font-awesome.min.css">
    <link rel="stylesheet" href="plugins/jqgrid/ui.jqgrid-bootstrap.css">
    <link rel="stylesheet" href="css/main.css">
    <script src="libs/jquery.min.js"></script>
    <script src="plugins/layer/layer.js"></script>
    <script src="libs/bootstrap.min.js"></script>
    <script src="libs/vue.min.js"></script>
    <script src="plugins/jqgrid/grid.locale-cn.js"></script>
    <script src="plugins/jqgrid/jquery.jqGrid.min.js"></script>
    <script src="js/common.js"></script>
</head>
<body>

<div id="app">
    <div class="panel panel-default">
        <div class="panel-heading">{{title}}</div>
        <form class="form-horizontal">

            <div class="form-group">
                <div class="col-sm-2 control-label">主路径</div>
                <div class="col-sm-10">
                    <input type="text" class="form-control" v-model="model.mainPath" placeholder="主路径"/>
                </div>
            </div>

            <div class="form-group">
                <div class="col-sm-2 control-label">包名</div>
                <div class="col-sm-10">
                    <input type="text" class="form-control" v-model="model.packageName" placeholder="包名"/>
                </div>
            </div>

            <div class="form-group">
                <div class="col-sm-2 control-label">模块名称</div>
                <div class="col-sm-10">
                    <input type="text" class="form-control" v-model="model.moduleName" placeholder="模块名称"/>
                </div>
            </div>

            <div class="form-group">
                <div class="col-sm-2 control-label">作者</div>
                <div class="col-sm-10">
                    <input type="text" class="form-control" v-model="model.author" placeholder="作者"/>
                </div>
            </div>

            <div class="form-group">
                <div class="col-sm-2 control-label">邮箱</div>
                <div class="col-sm-10">
                    <input type="text" class="form-control" v-model="model.email" placeholder="邮箱"/>
                </div>
            </div>

            <div class="form-group">
                <div class="col-sm-2 control-label">表映射前缀</div>
                <div class="col-sm-10">
                    <input type="text" class="form-control" v-model="model.tablePrefix" placeholder="表映射前缀"/>
                </div>
            </div>

            <div class="form-group">
                <div class="col-sm-2 control-label">项目文件后缀</div>
                <div class="col-sm-10">
                    <input type="text" class="form-control" v-model="model.suffix" placeholder="项目文件后缀"/>
                </div>
            </div>


            <div class="form-group">
                <div class="col-sm-2 control-label"></div>
                <input type="button" class="btn btn-primary" v-if="allowClick" @click="saveOrUpdate" value="确定"/>
                <input type="button" class="btn btn-primary" v-else disabled @click="saveOrUpdate" value="确定"/>
            </div>


        </form>
    </div>
</div>

<script type="text/javascript">

    var vm = new Vue({
        el: '#app'
        , data: {
            allowClick: true
            , title: '配置属性'
            , model: {}
        }
        , created: function () {
            this.reload();
        }
        , mounted: function () {
        }
        , methods: {
            reload: () => {
                $.get('/sys/conf/confget', r => vm.model = r.conf);
            }
            , saveOrUpdate:  event => {
                if (vm.allowClick) {
                    vm.allowClick = false;
                    $.ajax({
                        type: "POST",
                        url: '/sys/conf/conf',
                        contentType: "application/json",
                        data: JSON.stringify(vm.model),
                        success: (r) => {
                            vm.allowClick = true;
                            if (r.code === 0) {
                                alert('操作成功', function (index) {
                                    this.reload();
                                });
                            } else {
                                alert(r.msg);
                            }
                        }
                    });
                }
            },
        }
    });

</script>

</body>
</html>